<?php
if (!defined("EXPONENT")) exit("");
include(BASE . "modules/musicsmodule/core.php");
// 8/18/2009: Immanuel192 said: no flow
//exponent_flow_set(SYS_FLOW_PROTECTED,SYS_FLOW_ACTION);

$music = $db->selectObject("musics","id=" . intval($_GET['id']));
$db->increment('musics','listen_count',1,' id = '.intval($_GET['id']));

if ($music != null) {
	// get album
	$album = $db->selectObject('album',"id = {$music->album_id}");
	// get composer name
	$composer=$db->selectObject('composers',"id = {$music->composer_id}");
	$composer_name='';
	if ($composer)
		{
		$composer_name=$composer->name;
	}
	$music->composer_name =$composer_name;
	// for picpath
  if ($album->image_id == 0) {
		$album->picpath = '';
	} else {
		$file = $db->selectObject('file', 'id='.$album->image_id);
		$album->picpath = $file->directory.'/'.$file->filename;
	}
	// for music file
	if ($music->high_quality <= 0) {
		$music->high_quality = '';
	} else {
		$file = $db->selectObject('file', 'id='.$music->high_quality);
		$music->high_quality_id =$music->high_quality; 
		$music->high_quality = $file->directory.'/'.$file->filename;
	}
	if ($album->downloadable)
	 $music->downloadable = 1;
	else
	 $music->downloadable = 0;
	
	// 8/19/2009: Immanuel192 said: change style; not query all music, just previous and next music item
	// for all musics in this album
	$musics=$db->selectObjects('musics','album_id='.$music->album_id." AND ((rank=".($music->rank-1).") OR (rank=".($music->rank+1)."))");
	// 8/19/2009: immanuel192: not need this code
  /*for($j=0; $j<count($musics); $j++) {
    /*$album=$db->selectObject('listing','id ='.$musics[$j]->album_id);
	  //$musics[$j]->album_name = $album->name;
	   //$musics[$j]->downloadable=$album->downloadable;
	  // $musics[$j]->singer_search = htmlspecialchars($musics[$j]->singer);
				if ($musics[$j]->high_quality <= 0) {
				$musics[$j]->high_quality = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->high_quality);
				$musics[$j]->high_quality_id = $musics[$j]->high_quality;
				$musics[$j]->high_quality = $file->directory.'/'.$file->filename;
				  
				   $file_info = $getid3->analyze($musics[$j]->high_quality); 				  
				  //getid3_lib::CopyTagsToComments($file_info); 
				  $musics[$j]->bitrate=round($file_info['bitrate']/1000,0);
				  $musics[$j]->fileformat=$file_info['fileformat'];
				  $file_info=$file_info['playtime_string'];
				  $musics[$j]->file_length = $file_info;
				  
				  
				}
				
				if ($musics[$j]->sound_trackmix == 0) {
				$musics[$j]->sound_trackmix = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->sound_trackmix);
				$musics[$j]->sound_trackmix_id = $musics[$j]->sound_trackmix;
				$musics[$j]->sound_trackmix = $file->directory.'/'.$file->filename;
				
				
				}
				
				if ($musics[$j]->tongpho == 0) {
				$musics[$j]->tongpho = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->tongpho);
				$musics[$j]->tongpho_id = $musics[$j]->tongpho;
				$musics[$j]->tongpho = "http://" . $_SERVER['HTTP_HOST']."/giangdong/" .$file->directory.'/'.$file->filename;
				
				
				}
				
				if ($musics[$j]->sheet_music == 0) {
				$musics[$j]->sheet_music = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->sheet_music);
				$musics[$j]->sheet_music_id = $musics[$j]->sheet_music;
				$musics[$j]->sheet_music = $file->directory.'/'.$file->filename;
				}
				
				if ($musics[$j]->demo == 0) {
				$musics[$j]->demo = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->demo);
				$musics[$j]->demo_id = $musics[$j]->demo;
				$musics[$j]->demo = $file->directory.'/'.$file->filename;
				}
				
				// get composer name
				$composer=$db->selectObject('listing',"list_type = 1 AND id = {$musics[$j]->composer_id}");
				$composer_name='';
				if ($composer)
				{
					$composer_name=$composer->name;
				}
				$musics[$j]->composer_name =$composer_name;
				$musics[$j]->old_info =$musics[$j]->info;
				// for tooltip
				//  build tooltip info
				$musics[$j]=musicsmodule::make_info($musics[$j]);
				
				// what next?
				if ($musics[$j]->id == intval($_GET['id']))
					$music=$musics[$j];
			}*/
	$template = new template("musicsmodule",'_play_file');
	$template->assign('music',$music);
	$template->assign('album',$album);
	$template->assign('musics',$musics);
	/*
	$musics=array();
	$musics[0]=$music;
	//print_r($mu
	if (!isset($_REQUEST['play_type']))
		$_REQUEST['play_type']=-1;
	$play_type = intval($_REQUEST['play_type']);
	$file_name=create_playlist($musics,$play_type);
	$template->assign('plist',$file_name);
	$template->assign('play_type',$play_type);*/
	$template->register_permissions(array('administrate','configure'),$loc);
		
	$template->output();
} 
else {
	echo SITE_404_HTML;
}

?>
